package cn.qn.base;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.springframework.data.domain.PageRequest;

import java.io.Serializable;

public class BaseQuery implements Serializable{
    private static final long serialVersionUID = 474756371294953694L;
    private Integer page;
    private Integer size;

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public static PageRequest getPageRequest(Integer page, Integer size){
        if(null == page || page<=1){
            page = 0;
        }else{
            page = page -1;
        }
        if(null == size || size <1){
            size = 10;
        }
        return PageRequest.of(page,size);
    }

    public PageRequest getPageRequest(){
        Integer page = this.page;
        Integer size = this.size;
        if(null == page || page<=1){
            page = 0;
        }else{
            page = page -1;
        }
        if(null == size || size <1){
            size = 10;
        }
        return PageRequest.of(page,size);
    }

    public static PageBounds getPageBounds(Integer page,Integer size){
        if(null == page || page<=1){
            page = 1;
        }
        if(null == size || size <1){
            size = 10;
        }
        return new PageBounds(page,size);
    }


    public PageBounds getPageBounds(){
        Integer page = this.page;
        Integer size = this.size;
        if(null == page || page<=1){
            page = 1;
        }
        if(null == size || size <1){
            size = 10;
        }
        return new PageBounds(page,size);
    }
}
